<template>
  <footer class="footer">
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ unDoneTodoLength }}</strong> item left</span
    >
    <!-- Remove this if you don't implement routing -->
    <ul class="filters" @click="$emit('switch-todo', type)">
      <li>
        <a href="#/" :class="{ selected: type === 'all' }" @click="type = 'all'"
          >全部</a
        >
      </li>
      <li>
        <a
          href="#/active"
          :class="{ selected: type === 'no' }"
          @click="type = 'no'"
          >未完成</a
        >
      </li>
      <li>
        <a
          href="#/completed"
          :class="{ selected: type === 'yes' }"
          @click="type = 'yes'"
          >已完成</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button class="clear-completed" v-if="hasDoneTodo" @click="clearFn">
      清空
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      type: "all", //no,yes
    };
  },
  props: ["arr"],
  computed: {
    unDoneTodoLength() {
      return this.arr.filter((item) => item.isDone === false).length;
    },
    hasDoneTodo() {
      return this.arr.some((item) => item.isDone === true);
    },
  },
  methods: {
    clearFn() {
      if (window.confirm("确认要清空所以已完成的吗?")) {
        this.$emit("clear-todo");
      }
    },
  },
};
</script>

<style>
</style>
